﻿Imports System.Runtime.InteropServices

Public Class User32Wrappers

    Public Enum GWL As Integer
        ExStyle = -20
    End Enum

    Public Enum WS_EX As Integer
        Transparent = &H20
        Layered = &H80000
    End Enum

    Public Enum LWA As Integer
        ColorKey = &H1
        Alpha = &H2
    End Enum

    <DllImport("user32.dll", EntryPoint:="GetWindowLong")> _
    Public Shared Function GetWindowLong( _
        ByVal hWnd As IntPtr, _
        ByVal nIndex As GWL _
            ) As Integer
    End Function

    <DllImport("user32.dll", EntryPoint:="SetWindowLong")> _
    Public Shared Function SetWindowLong( _
        ByVal hWnd As IntPtr, _
        ByVal nIndex As GWL, _
        ByVal dwNewLong As WS_EX _
            ) As Integer
    End Function

    <DllImport("user32.dll", _
      EntryPoint:="SetLayeredWindowAttributes")> _
    Public Shared Function SetLayeredWindowAttributes( _
        ByVal hWnd As IntPtr, _
        ByVal crKey As Integer, _
        ByVal alpha As Byte, _
        ByVal dwFlags As LWA _
            ) As Boolean
    End Function


    Declare Auto Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Integer
    Declare Auto Function GetTopWindow Lib "user32" Alias "GetTopWindow" (ByVal hWnd As Integer) As Integer
    Declare Auto Function GetAncestor Lib "user32" Alias "GetAncestor" (ByVal hWnd As Integer, ByVal gaFlags As Int32) As Integer
    Declare Auto Function GetWindowTextLength Lib "User" (ByVal hWnd As Integer) As Integer
    Declare Auto Function GetWindowText Lib "user32.dll" (ByVal hwnd As Int32, <Out()> ByVal lpString As System.Text.StringBuilder, ByVal cch As Int32) As Int32
    Declare Auto Function GetWindowModuleFileName Lib "user32.dll" (ByVal hwnd As Int32, <Out()> ByVal pszFileName As System.Text.StringBuilder, ByVal cchFileNameMax As Int32) As Int32
    Declare Auto Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, ByVal lpdwprocessid As Long) As Long
    Declare Auto Function GetTickCount Lib "kernel32" () As Long
    Declare Auto Function GetLastInputInfo Lib "User32.dll" (ByRef lastInput As LASTINPUTINFO) As Boolean



End Class


<StructLayout(LayoutKind.Sequential)> _
Public Structure LASTINPUTINFO
    Public cbSize As Int32
    Public dwTime As Int32
End Structure

Public Class MyProcInfo
    Public ProcInfo As Process

    Private Sub New()
    End Sub

    Public Sub New(ByVal objProcInfo As Process)
        ProcInfo = objProcInfo
    End Sub

    Public Overrides Function ToString() As String
        Return DirectCast(IIf((ProcInfo.MainWindowHandle = IntPtr.Zero), "", "* "), String) & ProcInfo.ProcessName & " (" & ProcInfo.Id & ")"
    End Function
End Class